package jwdt.xadmin.added.action;

import jwdt.common.action.BaseAction;
import jwdt.common.util.CacheUtil;
import jwdt.xadmin.added.bean.TLink;
import jwdt.xadmin.added.service.LinkManageService;

import com.ezerg.db.Jdb;
import com.ezerg.db.ext.PageUtil;
import com.ezerg.web.Form;
import com.ezerg.web.Module;
import com.ezerg.web.Page;
import com.ezerg.web.annotation.Controller;
import com.ezerg.web.annotation.RequestMapping;

@Controller("/xadmin/added")
public class LinkManageAction extends BaseAction {
	
	private LinkManageService linkManageService = (LinkManageService)app.getBean("linkManageService");
	
	@RequestMapping("/listLink")
	public Page doList(Form f, Module m) throws Exception {
		PageUtil pu = (PageUtil)f.copy2Class(PageUtil.class);
		TLink l = (TLink)f.copy2Class(TLink.class);
		return m.getWritePage(f, linkManageService.doList(pu, l).toJson());
	}
	
	@RequestMapping("/addLink")
	public Page doAddact(Form f, Module m) throws Exception {
		TLink obj = (TLink)f.copy2Class(TLink.class);
		return m.getWritePage(f, linkManageService.doAddact(obj));
	}
	
	@RequestMapping("/editLink")
	public Page doEditact(Form f, Module m) throws Exception {
		int id = f.getInt("id");
		TLink obj = (TLink)f.copy2Class(TLink.class);
		return m.getWritePage(f, linkManageService.doEditact(obj, id));
	}
	
	@RequestMapping("/delLink")
	public Page doDel(Form f, Module m) throws Exception {
		int id = f.getInt("id");
		return m.getWritePage(f, linkManageService.doDelact(id));
	}
	
	@RequestMapping("/checkLink")
	public Page doUpdateState(Form f, Module m) throws Exception {
		int id = f.getInt("id");
		int result = f.getInt("result");
		return m.getWritePage(f, linkManageService.doUpdateState(id, "pass="+result));
	}
	
	@RequestMapping("/listLinkTypeForCombox")
	public Page doListForCombox(Form f, Module m) throws Exception {
		//生成json字符串
    	return m.getJsonPage(f, Jdb.get().query("select id, name from t_linktype ORDER BY id asc", CacheUtil.C0));
	}
	
	@RequestMapping("/linkWindow")
	public Page doLoad(Form f, Module m) throws Exception {
		int id = f.getInt("id");
		f.add("obj", linkManageService.doLoad(id));
		return m.findPage("/xadmin/added/linkWindow");
	}
}
